Introduction

XMR control charts are useful when determining if there are significant trends in data. XMR charts have two key assumptions: one is that the measurements of value happen over time, and the other is that each measurement of time has one measurement of value.

Take careful thought about what you are trying to measure with XMR. Proportions work best, headcount is okay, costs over time aren't great.


Arguments

The arguments for xmR() are as follows.

The data required for XMR charts take a specific format, with at least two columns of data - one for the time variable and another for the measurement. Like so:

library(sRa)
set.seed(1)
Measure <- round(runif(10, min = 0.50, max = 0.75)*100, 0)
Measure <- c(Measure, round(runif(8, min = 0.75, max = 1)*100, 0))
Time <- c(2000:2017) 
example_data <- data.frame(Time, Measure)
knitr::kable(example_data, format = "markdown", align = 'c')

The function use on this set of data would be written like this if we wanted the boundries to recalculate.

xmr_data <- xmR(df = example_data, measure = "Measure", recalc = T)

The measure column must be written within quotes.

Output data looks like this:

xmr_data <- xmR(df = example_data, measure = "Measure", recalc = T) %>% select(-Order)
knitr::kable(xmr_data, format = "markdown", align = 'c')

Charts

That data calculation is handy, but what about visualiztion?

There is a function called xmR_chart() which takes that output, and generates a ggplot graphic so the user can identify trends in the data.

The arguments for xmR_chart() are as follows.

xmR_chart(dataframe = xmr_data, time = "Time", measure = "Measure")

Other Packages

Simple datasets like those illustrated above are common, but more common are large datasets with multiple factors. Consider the following data. How would the xmR() function benefit the user in this case?

library(sRa)
library(air)
library(tidyverse)
lers_data <- get_enrolment("FLE", c("Gender"), c("MH")) %>% 
  mutate(`Academic Year` = gsub("-20", "-", `Academic Year`))
knitr::kable(lers_data, format = "markdown", align = 'c')

The answer is by leveraging other R packages, namely the tidyverse.

You can install and load the tidyverse by the following.

install.packages("tidyverse")
library(tidyverse)

What this enables is a number of verb-type functions for tidying and wrangling data. This is how to use them alongside the xmR() function.


Grouping and Faceting

Take our data of enrolment lers_data and here is how to apply the xmR() function to certain groups within that data.

lers_xmr <- lers_data %>% group_by(Gender) %>% do(xmR(., "FLE", recalc = T))
knitr::kable(lers_xmr, format = "markdown", align = 'c')

And as you may be able to see, the XMR data calculated on FLE AND by Gender, in one function instead of having to manually split the data. Now, if we tried to plot this data we would do the following.

xmR_chart(dataframe = lers_xmr, time = "Academic Year", measure = "FLE", facetvar = "Gender")


Zanidean/sRa documentation built on May 7, 2019, 7:44 a.m.